import React, { Component } from 'react'
import { Form, Input, Select } from 'antd'
import PropTypes from 'prop-types'
const Option = Select.Option
const Item = Form.Item


export default class Addfrom extends Component {
  static propTypes = {
    dataSource: PropTypes.array.isRequired
  }

  render() {
    return (
      <Form preserve={false}
        ref={this.props.addfrom}
        initialValues={{ parentId: this.props.parentId }}>
        <span>所属分类：</span>
        <Item name='parentId'>
          <Select style={{ width: "100%" }}>
            <Option key={0} value={0}>一级分类</Option>
            {
              this.props.dataSource.map((item, key) => {
                return (
                  <Option key={item._id} value={item._id}>{item.name}</Option>
                )
              })
            }
          </Select>
        </Item>
        <span>分类名称：</span>
        <Item name='parentName' rules={[{ required: true, message: '名称必须填写！' }]}>
          <Input autoComplete={'off'} placeholder='请输入分类名称' onPressEnter={this.props.adddata } />
        </Item>
      </Form>
    )
  }
}




